// 加载路由列表
let ROUTE_LIST = (state, payload) => {
    state.routes = [...payload];
    // 要浅拷贝一下，防止出现其他问题
}

// 更新路由
let EDIT_ROUTE = (state, payload) => {
    let index = state.routes.findIndex(routes => routes.route_id === payload.route_id);
    if (index !== -1) {
        // 使用 splice 方法更新数组，以便触发响应式更新机制
        state.routes.splice(index, 1, payload);
    }
}

// 添加路由
let ADD_ROUTE = (state, route) => {
    state.routes.push(route);
}

// 删除路由
let REMOVE_ROUTE = (state, route_id) => {
    let index = state.routes.findIndex(item => item.route_id === route_id);
    if (index !== -1) {
        state.routes.splice(index, 1);
    }
}

// 根据角色id，获取角色的路由权限
let ROUTE_POWER = (state, payload) => {
    state.route_power_list = [...payload];
}

export default {
    ROUTE_LIST,
    EDIT_ROUTE,
    ADD_ROUTE,
    REMOVE_ROUTE,
    ROUTE_POWER,
}